
const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');

// 执行命令
const execCommand = (command) => {
    exec(command, (error, stdout, stderr) => {
        if (error) {
            console.error(`执行出错: ${error}`);
            return;
        }
        console.log(`stdout: ${stdout}`);
        if (stderr) {
            console.log(`stderr: ${stderr}`);
        }
    });
}

// type 0|1  git|svn
const updateCode = (repository, filePath, type = 0) => {
    if (!fs.existsSync(filePath)) {
        // 拉取
        if (type === 0) execCommand(`git clone ${repository} ${filePath}`)
        if (type === 1) execCommand(`svn checkout ${repository} ${filePath}`)
    } else {
        // 更新
        if (type === 0) {
            execCommand(`cd ${filePath} && git pull origin main`)
        }
        if (type === 1) execCommand(`svn update ${filePath}`)
    }
}

// updateCode("https://gitlab.com/hy_software/hy_dev_lib.git", "./src/hy_dev_lib")
// 迁移到了gitee上
updateCode("https://gitee.com/Wanghuahuaa/hy_dev_lib.git", "./src/hy_dev_lib")
updateCode("https://win-g7536rmojnb/svn/gcfx_nuget/Knife.Web/ClientApp/gcfx_web", "./src/gcfx_web", 1)